{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#射击app\n",
    "\n",
    "前面提到过，在这一章我们来做射击（shoot-em-up，简写shmup）app，一个快节奏的射击游戏，比魂斗罗简单许多。\n",
    "\n",
    "<!-- TEASER_END-->\n",
    "\n",
    "![shmup](kbpic/9.1 shmup.png)\n",
    "\n",
    "做一个在屏幕上同时移动不同内容的游戏，需要大量的渲染来实现，在移动端（或多平台支持）也是如此。这一章我们就来做这些事情，上一章的知识和源代码已经带我们入了门。\n",
    "\n",
    "教学大纲如下：\n",
    "\n",
    "- 用Kivy的纹理图集（Texture atlases）完成本来需要用底层代码实现的纹理坐标值的设置工作\n",
    "- 继续用GLSL开发一个质点原型，然后用这个原型做不同的游戏角色\n",
    "- 实现二维射击游戏的——一个控件，鼠标和触摸屏，基本冲突发现子弹\n",
    "\n",
    "后面会涉及到大量细节，如果看不明白就运行一下文末的源代码。\n",
    "\n",
    "##项目的限制\n",
    "\n",
    "我们做的app比较简单，功能有限，至少有以下限制：\n",
    "\n",
    "- 为了简化，忽略了奖惩机制，2048里面也是这样\n",
    "- 这个游戏只有一个敌人角色，简单模式\n",
    "- 许多优化被忽略了，可以少写一些代码\n",
    "\n",
    "如果感兴趣可以自己做。下面我们来看一下Kivy的纹理处理相关内容，后面会用到。\n",
    "\n",
    "##纹理图集简介\n",
    "\n",
    "纹理图集（也叫sprite sheets）是一种应用开发中把图象组合成更大纹理的方法。与只是把一堆单个图象载入应用相比，这么做有些好处：\n",
    "\n",
    "- 应用打开更快，读一个大文件比读许多小文件要快。如果你有几百个这样的图片，用这种方法性能提升会很明显——网页上更是如此：图片太多会严重占用HTTP请求资源，在移动设备上这点更加明显\n",
    "- 一次性渲染也会很更快。用纹理映射可以只改变需要变化的纹理坐标，而不需要引起其他内容的变化\n",
    "- 当有一个大的模型时，像GLSL类的渲染，用纹理图集方法更适合。另外，纹理的坐标值更容易获取，也不需要二次绑定纹理\n",
    "\n",
    ">在HTML和CSS里面常用类似的方法，叫CSS图片合并（CSS sprites）。原理是一样的。网页app通常是获取网络资源，如果大量图片存在会占用HTTP请求数，用CSS图片合并可以很好的降低HTTP请求占用。\n",
    "\n",
    "这一章，我们要介绍以下内容：\n",
    "\n",
    "- 用Kivy的CLI工具创建纹理映射\n",
    "- 文件格式化和`.atlas`文件结构\n",
    "- Kivy应用纹理图集的用法\n",
    "\n",
    "如果你已经掌握了相关内容，可以直接跳到*GLSL使用纹理图集*一节。\n",
    "\n",
    "###创建一个图集\n",
    "\n",
    "和网页开发不同，那里没有标准工具处理这个任务，Kivy框架用一个命令行工具处理图集映射。\n",
    "\n",
    "```bash\n",
    "python –m kivy.atlas <atlas_name> <texture_size> <images…>\n",
    "```\n",
    "\n",
    "在Mac系统上，把`python`替换成`kivy`，因为安装的时候`Kivy.app`会调用Python解释器。\n",
    "\n",
    "这样会创建至少两个文件，由所有的图像是否满足一个设定大小的纹理来决定。本章假设`texture_size`的值足够包含所有图像。\n",
    "\n",
    "所有输出文件都是`atlas_name`开头的参数：\n",
    "\n",
    "- \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "[源代码](kbpic/src/9_ShootEmUp/)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
